<template>
    <button class="back-button" @click="goBack">
      <span class="btn-txt">BACK</span>
    </button>
  </template>
  
  <script setup lang="ts">
  import { useRouter, useRoute } from 'vue-router';
  
  const router = useRouter();
  const route = useRoute();
  
  const goBack = () => {
    try {
      if (route.path !== '/') {
        router.back();
      } else {
        router.push('/');
      }
    } catch (error) {
      console.error('Navigation error:', error);
      router.push('/');
    }
  };
  </script>
  
  <style scoped>
  .back-button {
    align-items: center;
    background-color: transparent;
    color: #cac706;
    cursor: pointer;
    display: flex;
    font: 700 1rem/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
    text-decoration: none;
    text-transform: uppercase;
    outline: 0;
    border: 0;
    padding: 0.25rem 0.5rem; /* 进一步减小内边距 */
    margin-right: 10px;
  }
  
  .back-button::before {
    background-color: #cac706;
    content: "";
    display: inline-block;
    height: 1px;
    margin-right: 0px;
    transition: width .42s cubic-bezier(.25,.8,.25,1);
    width: 0;
  }
  
  .back-button:hover::before {
    width: 2rem;
  }
  </style>